﻿<%@ Page Title="" Language="C#" MasterPageFile="~/uc/MemberIndex.Master" validateRequest="false" AutoEventWireup="true" CodeBehind="article_add.aspx.cs" Inherits="ncp.Web.member.article_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server">
<title>求购信息-中国农业信息化服务商</title>
<script src="/Plugin/ueditor/editor_config.js" type="text/javascript"></script>

    <link href="/Plugin/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
    <script src="/Plugin/ueditor/editor_all.js" type="text/javascript"></script>
    <link href="/Plugin/ueditor/themes/default/ueditor.css" rel="stylesheet" type="text/css" />
    <script src="/Plugin/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

    <script src="/Plugin/uploadify/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="bh-con-right-h-yy" id="mappath"><a href="#">店铺管理</a> > 信息发布</div>
<div id="item-publish">
    <div class="bd-main">
        <div class="title">信息发布</div>
        <div class="form mod-content">
            <table>
                <tr>
                    <td class="mod-label"> <em>*</em><label for="newsTitle">标题:</label></td>
                    <td><input type="text" class="bh-input-long" maxlength="50" id="newsTitle"/><span class="msg"></span></td>
                </tr>
                <tr>
                    <td class="mod-label"> <em>*</em><label for="proName">信息类型:</label></td>
                    <td>
                    <select class="bh-select" id="articleClass">
                        <option value="">--请选择--</option>
                    </select>
                    <span class="msg"></span>
                    </td>
                </tr>
                <tr>
                    <td class="mod-label" style="vertical-align:top;"> <label for="proName">文章图片:</label></td>
                    <td>
                        <div id="uploadify1">
                        </div>
                        <span class="msg"></span>
                        <ul id="imageList">
                        </ul>
                    </td>
                </tr>
                <tr>
                    <td class="mod-label" style="vertical-align:top;"><label for="proName">内容摘要:</label></td>
                    <td>
                        <textarea class="description" name="description" onkeyup="this.value = this.value.substring(0, 127)" rows="5" id="description"></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="mod-label" style="vertical-align:top;"><label for="proName">文章内容:</label></td>
                    <td id="news">
                    <script type="text/plain" id="newsContent">
                    </script></td>
                </tr>
                <tr>
            <td colspan="2" style="text-align: center;border-bottom: none;">
                <input type="button" class="bh-lr-btn" onclick="onSave()" value="保 存"/>
                <input type="button" class="bh-lr-btn" onclick="history.go(-1)" value="返 回"/>
            </td>
        </tr>
        <tr style="border: none;">
            <td colspan="2" style="border: none;">
                注：<br/>
                1、带*号的项为必填！<br/>
            </td>
        </tr>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    	//加载编辑器
    	var editor = new baidu.editor.ui.Editor({
    	toolbars: nomalToolbar,
    		minFrameHeight: 350,
    		elementPathEnabled: false
    	});
    	editor.render("newsContent");
    	function appendList(fileName, fileaddr) {
    	    //如果存在图片就删除原有图片
    	    if ($("#imageList li").length>0) {
    	        onDelete($(".imgdelete"));
    	    }
    	    var list = "<li><span title=\"删除\" onclick=\"onDelete(this)\" class=\"imgdelete\"></span><img  src=\"" + fileaddr + "\"/><div class=\"imgName\">" + fileName + "</div></li>";
    	    $("#imageList").html(list);
    	}
    	$(function() {
    	    getArticleType();
    	    initMapPath();
    	    var proid = '<%=Request.QueryString["artId"] %>';
    	    if (proid != '') {
    	        loadNewsInfo();
    	    }
    	    //获取cookie用户名
    	    $.ajax({
    	        url: "/handler/CookieHandler.ashx",
    	        type: "POST",
    	        dataType: "text",
    	        success: function(data) {
    	            if (data == "") {
    	                alert("获取用户信息失败，请退出重新登录！");
    	                return;
    	            }
    	            $("#uploadify1").uploadify({
    	                'swf': '/Plugin/uploadify/uploadify.swf',
    	                'auto': true,
    	                'fileTypeExts': '*.gif; *.jpg; *.png',
    	                'uploader': '/handler/UploadHandler.ashx',
    	                'multi': false,
    	                'formData': { 'folder': '/uploadFiles', 'uname': data },
    	                'buttonText': '本地图片',
    	                "fileSizeLimit":imgSizeLimit,
    	                'onUploadSuccess': function(file, d, response) {
    	                    if (response) {
    	                        if (data != '0') {
    	                            appendList(file.name, d);
    	                        } else {
    	                            alert("图片上传失败！");
    	                        }
    	                    }
    	                }
    	            });
    	        }
    	    });
    	});
    	function initMapPath() {
    	    var type = '<%=Request.QueryString["type"] %>';
    	    $("#articleClass").val(type);
    	    var text = "<a href=\"#\">店铺管理</a> ";
    	    switch (type) {
    	        case "001":
    	            text += "> <a href=\"/member/shop_buyingLeads.html\">求购信息</a> ";
    	            break;
    	        case "008":
    	            text += "> <a href=\"/member/shop_case.html\">成功案例</a> ";
    	            break;
    	        case "009":
    	            text += "> <a href=\"/member/shop_company.html\">企业动态</a> ";
    	            break;
    	        case "010":
    	            text += "> <a href=\"/member/shop_join.html\">招商加盟</a> ";
    	            break;
    	    }
    	    text += "> 信息发布";
    	    $("#mappath").html(text);
    	}
    	    //删除图片
    	    function onDelete(obj) {
    	        //删除服务器图片
    	        var src = $(obj).parents("li").children("img").attr("src");
    	        if (src == undefined || src == "") {
    	            $(obj).parents("li").remove();
    	            return;
    	        }
    	        $.ajax({
    	            url: "/handler/ImageDelete.ashx",
    	            type: "POST",
    	            dataType: "text",
    	            data: "imgsrc=" + src,
    	            success: function(data) {
    	                if (data == "1" || data == "0") {
    	                    $(obj).parents("li").remove();
    	                    if ($(".defTitle").length == 0) {
    	                        $("#imageList li:eq(0)").append("<div class=\"defTitle\">封面图片</div>");
    	                    }
    	                }
    	            }
    	        });
    	    }
    	    function getArticleType() {
    	        var response = ncp.Web.member.article_add.GetNewsType();
    	        if (response.value != "") {
    	            var jsonOBJ = eval(response.value)[0];
    	            if (jsonOBJ.isreload) {
    	                $("#articleClass").html(jsonOBJ.msg);
    	            } else {
    	                alert(jsonOBJ.msg);
    	            }
    	        }
    	    }
    	    //保存
    	    function onSave() {
    	        $("span.msg").text("");
    	        if ($.trim($("#newsTitle").val()) == "") {
    	            $("#newsTitle").next("span.msg").text("标题不能为空！");
    	            $("#newsTitle").focus();
    	            return;
    	        }
    	        if ($("#articleClass").val() == "") {
    	            $("#articleClass").next("span.msg").text("请选信息类型！");
    	            $("#articleClass").focus();
    	            return;
    	        }
    	        var ele = new Object();
    	        ele.newsId = '<%=Request.QueryString["artId"] %>';
    	        ele.newsTitle = $("#newsTitle").val();
    	        ele.newsType = $("#articleClass").val();
    	        ele.description = $("#description").val();
    	        ele.newsPic = $("#imageList li img").attr("src") == undefined ? "" : $("#imageList li img").attr("src");
    	        ele.newsContent = editor.getContent();
    	        var response = ncp.Web.member.article_add.OnSave($.objectToJson(ele));
    	        if (response.value != "") {
    	            var jsonOBJ = eval(response.value)[0];
    	            alert(jsonOBJ.msg);
    	            if (jsonOBJ.isreload) {
    	                if (ele.newsId == "") {
    	                    dataEmpty();
    	                }
    	                else {
    	                    history.go(-1);
    	                }
    	            }
    	        }
    	    }
    	    function dataEmpty() {
    	        $("#newsTitle,#articleClass,.description").val("");
    	        $("#imageList").html("");
    	        editor.setContent("");
    	    }
    	    //加载信息
    	    function loadNewsInfo() {
    	        var newsid = '<%=Request.QueryString["artId"] %>';
    	        var response = ncp.Web.member.article_add.GetNewsInfo(newsid);
    	        if (response.value != null) {
    	            var jsonOBJ = eval(response.value)[0];
    	            if (jsonOBJ.isreload) {
    	                $("#newsTitle").val(jsonOBJ.News_Title);
    	                $("#articleClass").val(jsonOBJ.NC_Code);
    	                $("#description").val(jsonOBJ.description);
    	                if (jsonOBJ.News_Picture != "") {
    	                    appendList("", jsonOBJ.News_Picture);
    	                }
    	                var news = "<script type=\"text/plain\" id=\"newsContent\">" + jsonOBJ.News_Note + "<\/script>";
    	                $("#news").html(news);
    	            } else {
    	            alert(jsonOBJ.msg);
    	            history.go(-1);
    	            }
    	        }
    	    }
    	    
</script>
</asp:Content>
